package com.example.myworkers.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.myworkers.dao.GoodsMapper;
import com.example.myworkers.model.Goods;
import com.example.myworkers.model.Grant;
import com.example.myworkers.service.GrantService;
import com.example.myworkers.dao.GrantMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
* @author 门硕然
* @description 针对表【grant】的数据库操作Service实现
* @createDate 2023-10-27 09:59:25
*/
@Service
public class GrantServiceImpl extends ServiceImpl<GrantMapper, Grant>
    implements GrantService{

   @Autowired
    private GrantMapper grantMapper;

    @Autowired
    private GoodsMapper goodsMapper;



   //添加
    @Override
    public int insertGrant(Grant grant) {
        int value=0;
        //id不为0
        if(grant.getGrantid()>=0)
        {
            //商品存在则添加
            if(goodsMapper.selectOneByGoodsid(grant.getGoodsid())!=null){
                value=grantMapper.insertSelective(grant);
            }
        }else {
            value=-1;
        }
        return value;
    }
    //查询
    @Override
    public Grant selectGrant(int id) {

        Grant grant=new Grant();
        //id不为0
        if (id!=0){
            grant=grantMapper.selectOneByGrantid(id);
        }
        return grant;

    }




    @Override
    public int updateGrant(Grant grant) {

        int value=0;
        //主键不为0
        if(grant.getGrantid()!=0) {
            //主键信息必须存在
            if(grantMapper.selectOneByGrantid(grant.getGrantid())!=null){
                value=grantMapper.updateSelective(grant);
            }
        }
        return value;

    }

    @Override
    public int deleteGrant(int id) {

        int value=0;
        //id不为0
        if(id!=0){
            value=grantMapper.deleteByGrantid(id);
        }
        return value;
    }




}




